package com.woniuxy.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.woniuxy.entity.QuestionOption;
import jdk.nashorn.internal.scripts.JS;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @BelongsProject: Online-education-examination-platform-back
 * @BelongsPackage: com.woniuxy.util
 * @Author: Banol Zi
 * @CreateTime: 2022-06-08  14:36
 * @Description: TODO
 * @Version: 1.0
 *
 * JSON样式
 * {
 *     "topic.getTopicId().1":{
 *             "topic":"1topic.getTopic()",
 *             "opList":[{
 *                 "id":1,
 *                 "opt":"",
 *                 "status":"",
 *                 "tid":""
 *             }],
 *             "text":null,
 *             "teid":"topic.getTeid()"
 *     },
 *     "topic.getTopicId().2":{
 *             "topic":"2topic.getTopic()",
 *             "opList":[{
 *                 "id":1,
 *                 "opt":"",
 *                 "status":"",
 *                 "tid":""
 *             }],
 *             "text":null
 *     }
 * }
 */
@Component
public class GeneratePaperJSON {

    private GeneratePaperJSON(){

    }
    public static Map<String,Object> ResultMap = new HashMap<>();

    public static void put(Integer id, String topic,List<QuestionOption> opList,String text,Integer teid,Integer typeId,Integer score){
        Map<String,Object> entry = new HashMap<>();
        entry.put("opList",opList);
        entry.put("topic",topic);
        entry.put("text",text);
        entry.put("teid",teid);
        entry.put("typeid",typeId);
        entry.put("score",score);
        JSONObject o = new JSONObject(entry);
        ResultMap.put(id.toString(),o);
    }

    public static String doGenerate() {
        JSONObject o = new JSONObject(ResultMap);
        String s = JSONObject.toJSONString(o);
        return s;
    }

    public static void clear(){
        ResultMap.clear();
    }
}
